//
//  BHTabBar.m
//  xinlangweibo0621
//
//  Created by boldseas on 2017/6/22.
//  Copyright © 2017年 renbohan. All rights reserved.
//

#import "BHTabBar.h"
#import <Masonry.h>
#import "UIView+Extension.h"

@interface BHTabBar()

@property (nonatomic,weak) UIButton* plusBtn;

@end

@implementation BHTabBar


-(instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        UIButton *plusBtn = [[UIButton alloc]init];
        [plusBtn setBackgroundImage:[UIImage imageNamed:@"tabbar_compose_button"] forState:UIControlStateNormal];
        [plusBtn setBackgroundImage:[UIImage imageNamed:@"tabbar_compose_button_highlighted"] forState:UIControlStateHighlighted];
        [plusBtn setImage:[UIImage imageNamed:@"tabbar_compose_icon_add"] forState:UIControlStateNormal];
        [plusBtn setImage:[UIImage imageNamed:@"tabbar_compose_icon_add_highlighted"] forState:UIControlStateHighlighted];
        CGRect plusbtnF = plusBtn.frame;
        plusbtnF.size = plusBtn.currentBackgroundImage.size;
        plusBtn.frame = plusbtnF;
        [self addSubview:plusBtn];
        self.plusBtn = plusBtn;
    }
    return self;
}

- (void)layoutSubviews{
    [super layoutSubviews];
    
    self.plusBtn.centerX = self.width * 0.5;
    self.plusBtn.centerY = self.height * 0.5;
    
    CGRect tabbarF = self.frame;
    
    CGFloat tabbarBtnW = tabbarF.size.width / 5;
    CGFloat tabbarBtnIndex = 0;
    for (UIView *subView in self.subviews) {
        Class class = NSClassFromString(@"UITabBarButton");
        if ([subView isKindOfClass:class]) {
            CGRect subViewF = subView.frame;
            subViewF.size.width = tabbarBtnW;
            subViewF.origin.x = tabbarBtnIndex * tabbarBtnW;
            tabbarBtnIndex++;
            if (tabbarBtnIndex == 2) {
                tabbarBtnIndex++;
            }
            subView.frame = subViewF;
        }
    }
}



@end
